var t = getApp(), a = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ a ],
    data: {
        gold: {},
        second: {},
        three: {},
        kwd: "",
        search: !1,
        projectList: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        var a = this;
        this.init(), t.city && t.point ? (this.setData({
            point: JSON.parse(t.point),
            city: t.city,
            appointmentLang: wx.getStorageSync("yz_basic_info").lang.appointment
        }), wx.setNavigationBarTitle({
            title: "热门" + this.data.appointmentLang.worker || ""
        }), this.getData()) : this._getLocation(function() {
            return a.getData();
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    bind: function(t) {
        this.setData({
            kwd: t.detail.value
        });
    },
    init: function() {
        this.setData({
            kwd: "",
            page: 1,
            isLoadMore: !1,
            total_page: 0,
            projectList: [],
            search: !1,
            gold: {},
            second: {},
            three: {}
        }), this.kwd = "", this.page = 1, this.isLoadMore = !1, this.total_page = 0, this.projectList = [], 
        this.search = !1, this.gold = {}, this.second = {}, this.three = {};
    },
    getData: function() {
        var a = this, e = this, i = t.getNetAddresss("plugin.appointment.frontend.worker.get-workers-by-name");
        t._getNetWork({
            url: i,
            data: {
                lng: this.data.point.lng,
                lat: this.data.point.lat,
                city_name: this.data.city,
                kwd: this.data.kwd,
                page: 1
            },
            success: function(t) {
                var i = t.data;
                e.setData({
                    search: !!a.data.kwd
                }), 1 == i.result ? (e.setData({
                    isLoadMore: !0,
                    total_page: i.data.last_page,
                    projectList: i.data.data,
                    gold: i.data.data[0],
                    second: i.data.data[1],
                    three: i.data.data[2]
                }), a.data.second || a.setData({
                    second: {}
                }), a.data.three || a.setData({
                    three: {
                        name: "null",
                        has_one_store: {},
                        tags: []
                    }
                }), a.setData({
                    appointmentLang: wx.getStorageSync("yz_basic_info").lang.appointment
                }), wx.setNavigationBarTitle({
                    title: "热门" + a.data.appointmentLang.worker
                })) : wx.showToast({
                    title: i.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var a = this;
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            var e = this.data.page + 1;
            this.setData({
                page: e
            });
            var i = t.getNetAddresss("plugin.appointment.frontend.worker.get-workers-by-name");
            t._getNetWork({
                url: i,
                data: {
                    lng: this.data.point.lng,
                    lat: this.data.point.lat,
                    city_name: this.data.city,
                    kwd: this.data.kwd,
                    page: this.data.page
                },
                success: function(t) {
                    var e = t.data;
                    if (1 == e.result) {
                        var i = e.data.data.concat(a.data.commentList);
                        a.setData({
                            commentList: i
                        });
                    } else {
                        wx.showToast({
                            title: e.msg,
                            icon: "none"
                        });
                        var n = a.data.page - 1;
                        a.setData({
                            page: n,
                            isLoadMore: !1
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    goBack: function() {
        getCurrentPages().length <= 1 ? wx.reLaunch({
            url: "/packageG/index/index"
        }) : wx.navigateBack({
            delta: 1
        });
    },
    gotoWorker: function(t) {
        var a = t.currentTarget.dataset.id, e = JSON.stringify(this.data.point);
        wx.navigateTo({
            url: "/packageE/appointment/technician_details/technician_details?worker_id=" + a + "&point=" + e
        });
    }
});